<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>方法 | eleTree2.0</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" type="image/png" href="/favicon.ico">
    <link rel="stylesheet" href="/eleTree/css/icon.css?v=2.2.12.1">
    <script src="/eleTree/eleTree.js?v=2.3.2.1"></script>
    <script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src = "https://hm.baidu.com/hm.js?7fcfe1e92263ed7399914905523c0c95";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script>
    <meta name="description" content="">
    <meta name="baidu-site-verification" content="IvAUSITvsn">
    <meta name="keywords" content="eleTree2.0在线文档">
    
    <link rel="preload" href="/assets/css/0.styles.aace74f1.css" as="style"><link rel="preload" href="/assets/js/app.480250c8.js" as="script"><link rel="preload" href="/assets/js/4.b0d5486a.js" as="script"><link rel="preload" href="/assets/js/43.ccc6eb23.js" as="script"><link rel="prefetch" href="/assets/js/10.a0b1a881.js"><link rel="prefetch" href="/assets/js/11.38a905a5.js"><link rel="prefetch" href="/assets/js/12.283c4f32.js"><link rel="prefetch" href="/assets/js/13.b9d56332.js"><link rel="prefetch" href="/assets/js/14.73379bc3.js"><link rel="prefetch" href="/assets/js/15.7f1deca5.js"><link rel="prefetch" href="/assets/js/16.68f9f651.js"><link rel="prefetch" href="/assets/js/17.1936bb47.js"><link rel="prefetch" href="/assets/js/18.b9d2e7ea.js"><link rel="prefetch" href="/assets/js/19.47022793.js"><link rel="prefetch" href="/assets/js/20.840dae7e.js"><link rel="prefetch" href="/assets/js/21.05ca35b5.js"><link rel="prefetch" href="/assets/js/22.430b273e.js"><link rel="prefetch" href="/assets/js/23.bc776c15.js"><link rel="prefetch" href="/assets/js/24.d4738935.js"><link rel="prefetch" href="/assets/js/25.75456f05.js"><link rel="prefetch" href="/assets/js/26.db4e6df0.js"><link rel="prefetch" href="/assets/js/27.c8722d8b.js"><link rel="prefetch" href="/assets/js/28.596bb539.js"><link rel="prefetch" href="/assets/js/29.b284c5db.js"><link rel="prefetch" href="/assets/js/3.b77c06cc.js"><link rel="prefetch" href="/assets/js/30.7cf1dbee.js"><link rel="prefetch" href="/assets/js/31.3c57113a.js"><link rel="prefetch" href="/assets/js/32.82dc2e02.js"><link rel="prefetch" href="/assets/js/33.30ba126c.js"><link rel="prefetch" href="/assets/js/34.91729efe.js"><link rel="prefetch" href="/assets/js/35.2f8f329a.js"><link rel="prefetch" href="/assets/js/36.65394400.js"><link rel="prefetch" href="/assets/js/37.90ca698e.js"><link rel="prefetch" href="/assets/js/38.026f7dad.js"><link rel="prefetch" href="/assets/js/39.415e4ced.js"><link rel="prefetch" href="/assets/js/40.d57633b1.js"><link rel="prefetch" href="/assets/js/41.857dbc9a.js"><link rel="prefetch" href="/assets/js/42.c849b4ba.js"><link rel="prefetch" href="/assets/js/5.31af0348.js"><link rel="prefetch" href="/assets/js/6.cc7f3865.js"><link rel="prefetch" href="/assets/js/7.56874f53.js"><link rel="prefetch" href="/assets/js/8.7615c930.js"><link rel="prefetch" href="/assets/js/9.6eb8268c.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.b0b0b3af.js">
    <link rel="stylesheet" href="/assets/css/0.styles.aace74f1.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">eleTree2.0</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"><div class="nav-item"><a href="/eleTree/installation.html" class="nav-link">
  eleTree2.0
</a></div><div class="nav-item"><a href="https://layuiextend.hsianglee.cn/eleTree/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  1.0版本
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/hsiangleev/eleTree" target="_blank" rel="noopener noreferrer" class="nav-link external">
  github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://hsianglee.cn" target="_blank" rel="noopener noreferrer" class="nav-link external">
  个人博客
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/eleTree/installation.html" class="nav-link">
  eleTree2.0
</a></div><div class="nav-item"><a href="https://layuiextend.hsianglee.cn/eleTree/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  1.0版本
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/hsiangleev/eleTree" target="_blank" rel="noopener noreferrer" class="nav-link external">
  github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://hsianglee.cn" target="_blank" rel="noopener noreferrer" class="nav-link external">
  个人博客
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <div class="advertise-top"><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins data-ad-client="ca-pub-2229355551485035" data-ad-slot="6395441907" class="adsbygoogle" style="display:inline-block;width:210px;height:100px"></ins> <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script></div> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>开发指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/eleTree/installation.html" class="sidebar-link">安装</a></li><li><a href="/eleTree/quickstart.html" class="sidebar-link">快速开始</a></li><li><a href="/eleTree/update-log.html" class="sidebar-link">更新日志</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>使用文档</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/eleTree/usedocs-attr.html" class="sidebar-link">属性</a></li><li><a href="/eleTree/usedocs-methods.html" aria-current="page" class="active sidebar-link">方法</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/eleTree/usedocs-event.html" class="sidebar-link">事件</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>示例</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/eleTree/demo-methods.html" class="sidebar-link">方法示例</a></li><li><a href="/eleTree/demo-icon.html" class="sidebar-link">自定义图标或图片</a></li><li><a href="/eleTree/demo-customText.html" class="sidebar-link">文本节点自定义</a></li><li><a href="/eleTree/demo-datatype.html" class="sidebar-link">pid结构的数据格式</a></li><li><a href="/eleTree/demo-rightmenu.html" class="sidebar-link">右键菜单</a></li><li><a href="/eleTree/demo-drag.html" class="sidebar-link">节点拖拽</a></li><li><a href="/eleTree/demo-lazyload.html" class="sidebar-link">懒加载</a></li><li><a href="/eleTree/demo-search.html" class="sidebar-link">树节点搜索</a></li><li><a href="/eleTree/demo-manydata.html" class="sidebar-link">大数据量渲染</a></li><li><a href="/eleTree/demo-sort.html" class="sidebar-link">树节点排序</a></li><li><a href="/eleTree/explain.html" class="sidebar-link">规则说明</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h3 id="方法"><a href="#方法" class="header-anchor">#</a> 方法</h3> <table><thead><tr><th>方法名</th> <th>说明</th> <th>参数</th></tr></thead> <tbody><tr><td>on</td> <td>事件回调</td> <td>(type, callback)1.事件名，2.触发事件时的回调函数；<a href="/eleTree/usedocs-event.html">查看更多</a></td></tr> <tr><td>getChecked</td> <td>获取复选框选中的节点信息</td> <td>(leafOnly, includeHalfChecked, includeHideChecked)1.是否只选中叶子节点，默认false，2.是否包括半选节点，默认false，3.是否包含隐藏节点，默认true</td></tr> <tr><td>setChecked</td> <td>设置复选框选中的节点</td> <td>(checkArr, isUnCheckAll)1.设置选中项数组，2.是否先清空原有的选中项，默认true</td></tr> <tr><td>unChecked</td> <td>取消复选框选中的节点</td> <td>(unCheckArr)1.取消选中的节点数组；不传参数则默认清空所有选中项；</td></tr> <tr><td>setAllChecked</td> <td>checkbox选中所有节点，除了禁用的节点</td> <td>—</td></tr> <tr><td>reverseChecked</td> <td>checkbox反选所有节点，除了禁用的节点</td> <td>—</td></tr> <tr><td>getRadioChecked</td> <td>获取单选框选中的节点信息</td> <td>(includeHideChecked)1.是否包含隐藏节点，默认true</td></tr> <tr><td>setRadioChecked</td> <td>设置单选框选中的节点</td> <td>(checkArr, isUnCheckAll)1.设置选中项数组，2.是否先清空原有的选中项，默认true</td></tr> <tr><td>unRadioChecked</td> <td>取消单选框选中的节点</td> <td>(unCheckArr)1.取消选中的节点数组；不传参数则默认清空所有选中项</td></tr> <tr><td>expandAll</td> <td>展开所有节点</td> <td>—</td></tr> <tr><td>unExpandAll</td> <td>合并所有节点</td> <td>—</td></tr> <tr><td>append</td> <td>添加子节点(<span style="color:#ff4200;">有两种格式</span>)</td> <td>A. (id, array/object)1.查找需要添加的节点id，2.添加的子节点数据数组；id传null或空字符串则会添加到根节点<br>B. (array/object)只传一个array/object参数则代表传入的为pid格式的数据，即在节点pid下添加子节点</td></tr> <tr><td>updateKeySelf</td> <td>更新当前节点数据或移动某些节点(<span style="color:#ff4200;">有两种格式</span>)</td> <td>A. (id, object)1.查找需要修改的节点id，2.需要修改的数据<br>B. (array/object)只传一个array/object参数则代表传入的为pid格式的数据，即修改id的数据，如果pid改变，则代表移动节点</td></tr> <tr><td>remove</td> <td>删除节点数据</td> <td>(removeArr)1.需要删除的节点id数组(可以移除多个节点)</td></tr> <tr><td>edit</td> <td>编辑节点</td> <td>(id, nodeType)1.需要编辑的节点id, 2. 当前编辑的节点类型，对应触发的回调事件名称，可选值(edit/add_child/add_before/add_after)</td></tr> <tr><td>insert</td> <td>在某个节点前后插入数据</td> <td>(id, array/object, type)1.查找需要添加的节点id，2.需要添加节点数据数组，3.类型，在当前节点前插入还是节点后插入，可选参数('before','after')，默认节点前</td></tr> <tr><td>reload</td> <td>重新渲染树节点</td> <td>(options)1.传入object，参数初始参数一致</td></tr> <tr><td>search</td> <td>搜索树节点</td> <td>(value, callback)1.需要搜索的文本信息，2. 传入的搜索条件，函数返回值为true则显示该节点；<a href="/eleTree/demo-search.html">查看更多</a></td></tr> <tr><td>getAllNodeData</td> <td>获取所有节点数据</td> <td>('c'/'p') 传入字符串'c'则返回的数据结构为父子结构，传入字符串'p'则返回pid格式的数据，默认为'c'</td></tr> <tr><td>copy</td> <td>复制节点</td> <td>(id) 1.需要复制的节点id</td></tr> <tr><td>cutPaste</td> <td>剪贴节点</td> <td>(id) 1.需要剪贴的节点id</td></tr> <tr><td>paste</td> <td>粘贴节点</td> <td>(id, nodeType) 1.需要粘贴到的节点id，2.粘贴到该节点的位置，可选参数('before','after','children')，默认children</td></tr> <tr><td>getClipboardData</td> <td>获取剪贴板数据</td> <td>移动或复制或剪贴节点都会把该节点复制到剪贴板，如果剪贴板没有数据，则返回null</td></tr> <tr><td>sort</td> <td>对某个节点的子节点排序</td> <td>(opts) 1.id:对某一个节点排序, 不传则对最外层节点;field:按某个字段排序;type:升序asc降序desc;depth:深度,不传则为所有子节点；<a href="/eleTree/demo-sort.html">查看更多</a></td></tr> <tr><td>setHighlightNode</td> <td>设置节点高亮</td> <td>传入节点id，传空字符串则取消节点高亮</td></tr> <tr><td>expandNode</td> <td>设置节点展开方法</td> <td>(id, isExpandParent, isExpandChild)1. 传入节点id数组，2. 展开节点的同时是否展开父节点，默认false，3. 展开节点的同时是否展开子节点，默认false</td></tr> <tr><td>unExpandNode</td> <td>设置节点合并方法</td> <td>(id, isUnExpandParent, isUnExpandChild)1. 传入节点id数组，2. 合并节点的同时是否合并父节点，默认false，3. 合并节点的同时是否合并子节点，默认false</td></tr></tbody></table></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">2/21/2022, 2:39:45 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/eleTree/usedocs-attr.html" class="prev">
        属性
      </a></span> <span class="next"><a href="/eleTree/usedocs-event.html">
        事件
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.480250c8.js" defer></script><script src="/assets/js/4.b0d5486a.js" defer></script><script src="/assets/js/43.ccc6eb23.js" defer></script>
  </body>
</html>
